package com.wans.guli.search.entity;

import lombok.Data;
import org.dromara.easyes.annotation.HighLight;
import org.dromara.easyes.annotation.IndexField;
import org.dromara.easyes.annotation.IndexId;
import org.dromara.easyes.annotation.IndexName;
import org.dromara.easyes.annotation.rely.FieldType;
import org.dromara.easyes.annotation.rely.IdType;

import java.math.BigDecimal;
import java.util.List;

@Data
@IndexName(value = "product") // 替换为实际索引名
public class SkuEntity {

    @IndexId(type = IdType.CUSTOMIZE)
    private Long id;

    @IndexField(fieldType = FieldType.LONG, value = "skuId")
    private Long skuId;

    @IndexField(fieldType = FieldType.KEYWORD, value = "spuId")
    private String spuId;

    @IndexField(fieldType = FieldType.TEXT, value = "skuTitle", analyzer = "ik_smart")
    @HighLight(preTag = "<b style='color:red'>", postTag = "</b>", mappingField = "highlightContent")
    private String skuTitle;

    // 注意：price定义为keyword而非数值类型（如double）
    @IndexField(fieldType = FieldType.KEYWORD, value = "skuPrice")
    private BigDecimal  skuPrice;

    @IndexField(fieldType = FieldType.KEYWORD, value = "skuImg")
    // 不可查、不可聚合
    private String skuImg;

    @IndexField(fieldType = FieldType.LONG, value = "saleCount")
    private Long saleCount;

    @IndexField(fieldType = FieldType.BOOLEAN, value = "hasStock")
    private Boolean hasStock;

    @IndexField(fieldType = FieldType.LONG, value = "hotScore")
    private Long hotScore;

    @IndexField(fieldType = FieldType.LONG, value = "brandId")
    private Long brandId;

    @IndexField(fieldType = FieldType.LONG, value = "catalogId")
    private Long catalogId;

    @IndexField(fieldType = FieldType.KEYWORD, value = "brandName")
    // 不可查、不可聚合
    private String brandName;

    @IndexField(fieldType = FieldType.KEYWORD, value = "brandImg")
    // 不可查、不可聚合
    private String brandImg;

    @IndexField(fieldType = FieldType.KEYWORD, value = "catalogName")
    // 不可查、不可聚合
    private String catalogName;

    // 嵌套类型必须使用@NestedField注解
    @IndexField(value = "attrs", fieldType = FieldType.NESTED, nestedClass = Attr.class)
    private List<Attr> attrs;

    // 嵌套属性内部类
    @Data
    public static class Attr {
        @IndexField(fieldType = FieldType.LONG, value = "attrId")
        private Long attrId;

        @IndexField(fieldType = FieldType.KEYWORD, value = "attrName")
        // 不可查、不可聚合
        private String attrName;

        @IndexField(fieldType = FieldType.KEYWORD, value = "attrValue")
        private String attrValue;
    }

    /**
     * 高亮返回值被映射的字段
     */
    private String highlightContent;
}